package com.ruoyi.settlement.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.settlement.domain.AmSettlementVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.settlement.mapper.AmSettlementMapper;
import com.ruoyi.settlement.domain.AmSettlement;
import com.ruoyi.settlement.service.IAmSettlementService;

/**
 * 结算单管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-07-29
 */
@Service
public class AmSettlementServiceImpl implements IAmSettlementService 
{
    @Autowired
    private AmSettlementMapper amSettlementMapper;

    /**
     * 查询结算单管理
     * 
     * @param id 结算单管理ID
     * @return 结算单管理
     */
    @Override
    public Map<String, Object> selectAmSettlementById(Long id)
    {
        return amSettlementMapper.selectAmSettlementById(id);
    }

    /**
     * 查询结算单管理列表
     * 
     * @param amSettlement 结算单管理
     * @return 结算单管理
     */
    @Override
    public List<AmSettlementVo> selectAmSettlementList(AmSettlementVo amSettlement)
    {
        amSettlement.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
        return amSettlementMapper.selectAmSettlementList(amSettlement);
    }

    /**
     * 新增结算单管理
     * 
     * @param amSettlement 结算单管理
     * @return 结果
     */
    @Override
    public int insertAmSettlement(AmSettlement amSettlement)
    {
        amSettlement.setCreateTime(new Date());
        return amSettlementMapper.insertAmSettlement(amSettlement);
    }

    /**
     * 修改结算单管理
     * 
     * @param amSettlement 结算单管理
     * @return 结果
     */
    @Override
    public int updateAmSettlement(AmSettlement amSettlement)
    {
        if ( 3 == amSettlement.getStatus()){
            amSettlement.setConfirmTime(new Date());
        }
        return amSettlementMapper.updateAmSettlement(amSettlement);
    }

    /**
     * 批量删除结算单管理
     * 
     * @param ids 需要删除的结算单管理ID
     * @return 结果
     */
    @Override
    public int deleteAmSettlementByIds(Long[] ids)
    {
        return amSettlementMapper.deleteAmSettlementByIds(ids);
    }

    /**
     * 删除结算单管理信息
     * 
     * @param id 结算单管理ID
     * @return 结果
     */
    @Override
    public int deleteAmSettlementById(Long id)
    {
        return amSettlementMapper.deleteAmSettlementById(id);
    }

    /**
     * 查看审核情况
     * @return 结果
     */
    @Override
    public HashMap<String, Object> getAuditSituation() {
        HashMap<String,Object> result = new HashMap<String, Object>(16);
        Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
        result.put("toBePaid",amSettlementMapper.getAuditSituation(1,deptId));
        result.put("paiding",amSettlementMapper.getAuditSituation(2,deptId));
        result.put("paided",amSettlementMapper.getAuditSituation(3,deptId));
        return result;
    }
}
